package independence.hibernate;

import java.io.Serializable;
import java.util.List;

/**
 * The abstract base class for Hibernate DAO service access layers. Extend this class
 * to easily create service layers for your Hibernate DAO's.
 *
 * @param <T>	The type of object which this service layer operates upon.
 * @param <DAO>	The type of the DAO you will be injecting into this instance. (It must implement GenericDAO)
 * @param <ID>	The type of the persistent object's id field.
 * 
 * @author TK, TK Assembled.
 */
public abstract class GenericServiceLayerImpl<T, DAO extends GenericDAO<T, ID>, ID extends Serializable> implements GenericServiceLayer<T, DAO, ID> {
	/**
	 * The GenericDAO by which to perform persistence operations upon.
	 */
	protected DAO dao;
	/** {@inheritDoc} */
	@Override public void delete(T value) {
		this.dao.delete(value);
	}
	/** {@inheritDoc} */
	@Override public List<T> getAll() {
		return this.dao.getAll();
	}
	/** {@inheritDoc} */
	@Override public List<T> getAllByAttribute(String name, Object value) {
		return this.dao.getAllByAttribute(name, value);
	}
	/** {@inheritDoc} */
	@Override public T getByAttribute(String name, Object value) {
		return this.dao.getByAttribute(name, value);
	}
	/** {@inheritDoc} */
	@Override public T getById(ID value) {
		return this.dao.getById(value);
	}
	/** {@inheritDoc} */
	@Override public void persist(T value) {
		this.dao.persist(value);
	}
	/** {@inheritDoc} */
	@Override public void persistOrUpdate(T value) {
		this.dao.persistOrUpdate(value);
	}
	/** {@inheritDoc} */
	@Override public void update(T value) {
		this.dao.update(value);
	}
	/** {@inheritDoc} */
	@Override public void setDao(DAO dao) {
		this.dao = dao;
	}
}
